import React from 'react';
import ReactDOM from 'react-dom';
import { ConfigProvider } from 'antd';
import zhCN from 'antd/es/locale/zh_CN';
import moment from 'moment';
import 'moment/locale/zh-cn';

moment.locale('zh-cn');

import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

import axios from '@src/lib/axios';

async function login() {
    let loginInfo = await axios.post('/user/login', {
        username: 'admin2',
        password: 'admin123',
        serial_number: 'ABC',
        source: 'web'
    });
    if (loginInfo.code === 0) {
        localStorage.setItem('_token', JSON.stringify(loginInfo.data));
    }
    initApp();
}

/*
if (localStorage.getItem('_token')) {
    initApp();
} else {
    login();
}
*/

initApp();
function initApp() {
    ReactDOM.render(
        /*<React.StrictMode>
            <App />
        </React.StrictMode>*/
        <ConfigProvider locale={zhCN}>
            <App/>
        </ConfigProvider>,
        document.getElementById('root')
    );

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
    serviceWorker.unregister();
}

